package com.fxhy.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.fxhy.bean.AgentUser;
import com.fxhy.contants.Constants;
import com.fxhy.service.IndexService;
import com.fxhy.service.UserService;
import com.fxhy.vo.ResponseBodyEntity;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@RestController
@Api(value="首页接口")
@RequestMapping("index")
@Slf4j
public class IndexApi {
	@Autowired
	private UserService userService;
	
	@Autowired
	private IndexService indexService;
	
	@ApiOperation("查询首页数据报表")
	@RequestMapping(value = "recordData",method = RequestMethod.POST)
	public ResponseBodyEntity recordData(String phoneNum,String token) throws Exception{
		ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
		
		AgentUser userInfo = userService.findUserByPhone(phoneNum);
		if(userInfo != null && userInfo.getUserId() != null){
			responseBodyEntity.setData(indexService.findIndexData(userInfo.getUserId()));
			responseBodyEntity.setMsg("首页查询成功!");
			responseBodyEntity.setState(Constants.SUCCEED);
		}else{
			responseBodyEntity.setData("/login");
			responseBodyEntity.setMsg("登录失效!请重新登录!");
			responseBodyEntity.setState(Constants.FAILURE);
		}
		return responseBodyEntity;
	}
}
